package com.portal.controller;

import com.portal.common.Result;
import com.portal.entity.CompanyInfo;
import com.portal.entity.Milestone;
import com.portal.entity.TeamMember;
import com.portal.entity.Certificate;
import com.portal.service.CompanyInfoService;
import com.portal.service.MilestoneService;
import com.portal.service.TeamMemberService;
import com.portal.service.CertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 关于我们Controller
 */
@Api(tags = "关于我们接口")
@RestController
@RequestMapping("/about")
@CrossOrigin
public class AboutController {
    
    @Autowired
    private CompanyInfoService companyInfoService;
    
    @Autowired
    private MilestoneService milestoneService;
    
    @Autowired
    private TeamMemberService teamMemberService;
    
    @Autowired
    private CertificateService certificateService;
    
    /**
     * 获取公司信息
     */
    @ApiOperation("获取公司信息")
    @GetMapping("/company")
    public Result<CompanyInfo> getCompanyInfo() {
        try {
            CompanyInfo companyInfo = companyInfoService.getEnabledCompanyInfo();
            if (companyInfo == null) {
                companyInfo = new CompanyInfo();
                companyInfo.setName("西安力望电子科技有限公司");
                companyInfo.setPhone("029-88776655");
                companyInfo.setEmail("contact@liwang.com");
                companyInfo.setAddress("陕西省西安市高新区科技五路8号数字大厦");
            }
            return Result.success(companyInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取公司信息失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取发展历程
     */
    @ApiOperation("获取发展历程")
    @GetMapping("/milestones")
    public Result<List<Milestone>> getMilestones() {
        try {
            List<Milestone> milestones = milestoneService.getMilestoneList();
            return Result.success(milestones);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取发展历程失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取团队成员
     */
    @ApiOperation("获取团队成员")
    @GetMapping("/team")
    public Result<List<TeamMember>> getTeamMembers() {
        try {
            List<TeamMember> teamMembers = teamMemberService.getTeamMemberList();
            return Result.success(teamMembers);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取团队成员失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取关于我们页面所有数据
     */
    @ApiOperation("获取关于我们页面数据")
    @GetMapping
    public Result<Map<String, Object>> getAboutData() {
        try {
            Map<String, Object> data = new HashMap<>();
            
            // 获取公司信息
            CompanyInfo companyInfo = companyInfoService.getEnabledCompanyInfo();
            if (companyInfo == null) {
                companyInfo = new CompanyInfo();
                companyInfo.setName("西安力望电子科技有限公司");
                companyInfo.setPhone("029-88888888");
                companyInfo.setEmail("contact@example.com");
                companyInfo.setAddress("陕西省西安市高新区");
            }
            data.put("companyInfo", companyInfo);
            
            // 获取发展历程
            List<Milestone> milestones = milestoneService.getMilestoneList();
            data.put("milestones", milestones);
            
            // 获取团队成员
            List<TeamMember> teamMembers = teamMemberService.getTeamMemberList();
            data.put("teamMembers", teamMembers);
            
            // 获取公司资质
            List<Certificate> certificates = certificateService.getCertificateList();
            data.put("certificates", certificates);
            
            return Result.success(data);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取关于我们页面数据失败：" + e.getMessage());
        }
    }
} 